<?php 
/*
//INCLUINDO ARQUIVOS EXTERNOS
*/
require_once "includes/head.php"; 
require_once "includes/header.php";
require_once "includes/sidebar.php";
require_once "classes/Administrador.php"; //ARQUIVO DA CLASSE

$admin = new Administrador();//INSTANCIANDO A CLASSE

if((isset($_POST['cadastrar'])) || (isset($_POST['editar'])))
{		
	if(isset($_POST['editar']))
		$admin->Carregar($_POST['confirma-atualizacao']);
	$admin->SetSenhaConfirma($_POST['senha_confirma']);
	$admin->SetSenha($_POST['senha']);
	$admin->SetEmail($_POST['email']);
	$admin->SetNome($_POST['nome']);
	
	$admin->Salvar();
}


if($_GET)
{
	$acao = "cadastrar";
	/*
	//************************************************************EXCLUIR*****************************************************
	*/
	if($_GET['funcao'] == 'excluir')
	{		
		$_id = $_GET['id'];
		$admin->Excluir($_id);			
	}
	/*
	//************************************************************CADASTRAR OU EDITAR*****************************************************
	*/
	elseif($_GET['funcao'] == 'editar')
	{
		$acao = "editar";		
		$_id = $_GET['id'];
		$admin->Carregar($_id);		
	}
?>

	<div class="panel-wrapper">	
		<div class="panel-wrapper fixed">	        
			<div class="panel">
				
				<div class="title">
					<h4><?php echo $acao;?> administrador</h4>	
				</div>
	            
	            <div id="Msg-error"><?php echo $admin->GetErrorMsg(); ?></div><!-- MOSTRAR MsgAlerta DE VALIDACAO -->
				
				<form action="" method="post">					
					
					<div class="group fixed">
						<label for="nome">Nome:</label>
						<input type="text" name="nome" id="nome" maxlength="35" size="60" value="<?php echo $admin->GetNome(); ?>">
					</div>
					
					<div class="group fixed">
						<label for="email">E-mail:</label>
						<input type="text" name="email" id="email" maxlength="65" value="<?php echo $admin->GetEmail(); ?>">
					</div>
										
                    <div class="group fixed">
						<label for="senha">Senha:</label>
						<input type="password" name="senha" id="senha" maxlength="18" style="width:150px;">
					</div> 
					
                    <div class="group fixed">
						<label for="confirmar-senha">Confirmar Senha:</label>
						<input type="password" name="senha_confirma" id="confirmar-senha" maxlength="18" style="width:150px;">
					</div>  
					
                    <input type="submit" id="comparar-senha" name="<?php echo $acao;?>" value="<?php echo $acao;?>" class="button-red" />
                    <input type="hidden" value="<?php echo $_id; ?>" name="confirma-atualizacao" /><!-- PASSA O ID PELO HIDDEN NA CONFIRMAÇÃO DO CLICK -->
                    <a href='administrador.php' alt='voltar' class="button-white">Voltar</a>                                      
				</form>		
			</div><!-- panel -->
			<div class="shadow"></div>		
			<a href='administrador.php' alt='voltar' class="button-back">Voltar</a>
		</div><!-- panel-wrapper fixed -->	
	</div><!-- panel-wrapper -->

<?php		
}
//************************************************************LISTAR*****************************************************/
else
	$admin->Listar();

	require_once "includes/footer.php"; 
?>